package 算法.练习1;

import java.util.Scanner;

/**
 * @author:谢君臣
 * @Date:2021/7/15-14:47
 * @version:1.0
 * @function:
 */
public class D2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int V = in.nextInt();
        int[]v = new int[N+1];
        int[]p = new int[N+1];
        for (int i = 1; i <= N; i++) {
            v[i] = in.nextInt();
            p[i] = in.nextInt();
        }
        in.close();
        int[][]dp = new int[N+1][V+1];
        for (int i = 1; i <= N ; i++) {
            for (int j = 0; j <= V ; j++) {
                if (j>=v[i]){
                    dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j-v[i]] + p[i]);
                }else{
                    dp[i][j] = dp[i-1][j];
                }
            }
        }
        System.out.println(dp[N][V]);
    }

}
